import java.util.Arrays;

public class Test {
    public static void shellSort(int[] arr) {
        int gap = arr.length;
        while (gap != 1) {
            gap /= 2;
            shellSortInsert(arr,gap);
        }
    }

    private static void shellSortInsert(int[] arr, int gap) {
        for (int i = gap; i < arr.length; i++) {
            int j = i-gap;
            int tmp = arr[i];
            for (; j >= 0; j -= gap) {
                if (tmp < arr[j]) {
                    arr[j+gap] = arr[j];
                }else {
                    break;
                }
            }
            arr[j+gap] = tmp;
        }
    }

    private static void swap(int[] arr, int i, int j) {
        int tmp = arr[i];
        arr[i] = arr[j];
        arr[j] = tmp;
    }

    public static void main(String[] args) {
        int[] arr = {23,122,0,12,5657,12,48,-14,2,7,2,19,24,26,10,88,66,16};
        shellSort(arr);
        System.out.println(Arrays.toString(arr));
    }
}